//
//  BasePageViewController.m
//  NewApp
//
//  Created by  on 12-6-15.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BasePageViewController.h"
#import "BackgoundImageView.h"

@implementation BasePageViewController

@synthesize titleLabel;
@synthesize engine = engine_;

#pragma mark -
#pragma mark - Views lifecycle and memory management

- (void)viewDidLoad {
    [super viewDidLoad];
	
    //Set background 
    BackgoundImageView *bgImageView =[[BackgoundImageView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bgImageView];
    

    //Build title label
    UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page_name_bg.png"]];
    [self.view addSubview:titleImageView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 26.f)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    self.titleLabel = label;
    [label release];
    [self.view addSubview:self.titleLabel];
    
    [self.view sendSubviewToBack:self.titleLabel];
    [self.view sendSubviewToBack:titleImageView];
    [self.view sendSubviewToBack:bgImageView];
    
    
    [titleImageView release];
    [bgImageView release];
    
    
    UIView *fakeTitleView = [[UIView alloc] initWithFrame:CGRectZero];
    fakeTitleView.backgroundColor = [UIColor clearColor];
    self.navigationItem.titleView = fakeTitleView;
    [fakeTitleView release];
    
    //self.title = @"返回";

}

- (void) dealloc {
    [titleLabel release];
    [engine_ setDelegate:nil];
    NA_RELEASE_SAFELY(engine_);
    [super dealloc];
}

#pragma mark -
#pragma mark - Readonly property acessory

- (RequestEngine *) engine {
    if (nil == engine_) {
        engine_ = [[RequestEngine alloc] initWithTarget:self action:@selector(requestDidFinished:withObject:)];
    }
    
    return engine_;
}

#pragma mark -
#pragma mark - Callbacks

- (void) requestDidFinished:(RequestEngine *) reqEngine withObject:(id) object{
    //Subclass should override this method
}


@end
